<template>
  <div>
    <el-link
      v-for="file in fileList"
      :href="file.url"
      target="_blank"
      type="primary"
      >{{ file.name }}</el-link
    >
  </div>
</template>

<script>
export default {
  name: "HzImg",
  props: {
    src: {
      type: String,
      default: "",
    },
  },
  data() {
    return {};
  },
  watch: {},
  computed: {
    fileList: {
      get: function () {
        //必须有返回值，用来获取属性，称为get函数
        if (!this.src) {
          return [];
        }
        let result = this.src.split(",");
        let fileList = [];
        for (let i = 0; i < result.length; i++) {
          let url = result[i];
          if (url.indexOf("?") != -1) {
            url = url.split("?")[1];
          }
          let segs = url.split("/");
          let fileName = segs[segs.length - 1];
          let obj = {
            name: fileName,
            url: result[i],
          };
          fileList.push(obj);
        }
        return fileList;
      },
    },
    firstImage: {
      get: function () {
        //必须有返回值，用来获取属性，称为get函数
        if (!this.src) {
          return "";
        }
        let result = this.src.split(",");
        return result[0];
      },
    },
  },

  created() {},
  methods: {},
};
</script>
